package com.xrz.sxm.aj.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xrz.sxm.aj.activity.R;
import com.xrz.sxm.aj.entity_tab.Cpmxb;
import com.xrz.sxm.aj.entity_tab.DBHelps;
import com.xrz.sxm.aj.utils.Utils;
import com.xrz.sxm.aj.utils.XUtilBitmapUtil;

import java.util.List;

public class Adapter_Exap extends BaseExpandableListAdapter {

	private Context ctx;
	private DBHelps m_DbHelps;
	private List<Cpmxb> datas;

	public Adapter_Exap(Context ctx) {
		this.ctx = ctx;
		m_DbHelps = new DBHelps(ctx);
		datas = m_DbHelps.GetChanPinDatas();
	}

	@Override
	public Object getChild(int arg0, int arg1) {
		return null;
	}

	@Override
	public long getChildId(int arg0, int arg1) {
		return 0;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
							 boolean arg2, View arg3, ViewGroup arg4) {
		Cpmxb cpmxb = datas.get(groupPosition);
		if(arg3 == null){
			arg3 = LayoutInflater.from(ctx).inflate(R.layout.item_childview,null);
		}
		ImageView image = (ImageView) arg3.findViewById(R.id.imageview);
		TextView text = (TextView) arg3.findViewById(R.id.tv_text);
		XUtilBitmapUtil.getInstant().displayByWidth(ctx, image, cpmxb.tplj);
		text.setText(Utils.replaceChar(cpmxb.cpjs));
		return arg3;
	}

	@Override
	public int getChildrenCount(int arg0) {
		return 1;
	}

	@Override
	public Object getGroup(int arg0) {
		return null;
	}

	@Override
	public int getGroupCount() {
		return datas.size();
	}

	@Override
	public long getGroupId(int arg0) {
		return 0;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded, View arg2,
							 ViewGroup arg3) {
		Cpmxb cpmxb = datas.get(groupPosition);
		if(arg2 == null){
			arg2 = LayoutInflater.from(ctx).inflate(R.layout.item_grounpview, null);
		}
		TextView tv_name = (TextView) arg2.findViewById(R.id.tv_name);
		TextView tv_jiajian = (TextView) arg2.findViewById(R.id.tv_jiajian);
		tv_name.setText(cpmxb.cpmc);
		if (isExpanded)
			tv_jiajian.setText("-");
		else
			tv_jiajian.setText("+");
		return arg2;
	}

	@Override
	public boolean hasStableIds() {
		return false;
	}

	@Override
	public boolean isChildSelectable(int arg0, int arg1) {
		return false;
	}

}
